﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using BUS;
using DTO;
using System.Windows.Forms;

namespace GiaoDien
{
    public partial class FormChucVu : Form
    {
        private DataTable datatable;
        private string sqlquery;
        public FormChucVu()
        {
            InitializeComponent();
        }
        private void init()
        {
            datatable = new DataTable();
        }
        private void xemtatca()
        {
            CHUCVUBUS bpBUS = new CHUCVUBUS();
            datatable = bpBUS.Loadchucvu();
            this.dataGridView1.DataSource = datatable;
        }
        private void btnlapthe_Click(object sender, EventArgs e)
        {
            CHUCVUDTO bpDTO = new CHUCVUDTO();
            bpDTO.Machucvu = tbmachucvu.Text.Trim().ToUpper();
            bpDTO.Tenchucvu = tbtenchucvu.Text.Trim().ToUpper();
            CHUCVUBUS bpBUS = new CHUCVUBUS();
            int kq = bpBUS.themchucvu(bpDTO);
            if (kq > 0)
                MessageBox.Show("thêm thành công");
            else
                MessageBox.Show("thêm thất bại");
            xemtatca();
        }

        private void FormChucVu_Load(object sender, EventArgs e)
        {
            init();
            xemtatca();
        }

        private void btnxemtatca_Click(object sender, EventArgs e)
        {
            xemtatca();
        }

        private void btncapnhat_Click(object sender, EventArgs e)
        {
            CHUCVUBUS bpBUS = new CHUCVUBUS();
            sqlquery = "SELECT * FROM CHUC_VU";
            int kq = bpBUS.update(datatable, sqlquery);
            if (kq > 0)
                MessageBox.Show("Thành công");
            else
                MessageBox.Show("Thất bại");
            xemtatca();
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        
       

        
    }
}
